package com.example.shishaolong.warehousemanager;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.shishaolong.warehousemanager.common.DateUtil;
import com.example.shishaolong.warehousemanager.common.SystemConst;
import com.example.shishaolong.warehousemanager.dao.AdminDao;
import com.example.shishaolong.warehousemanager.dao.GoodsDao;
import com.example.shishaolong.warehousemanager.entity.AdminEntity;
import com.example.shishaolong.warehousemanager.entity.GoodsEntity;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    /**
     * 登录操作
     * @param view
     */
    public void login(View view){

        AdminDao adminDao = new AdminDao(this);

        EditText userName = (EditText) findViewById(R.id.login_name_value);
        EditText passWord = (EditText) findViewById(R.id.login_password_value);

        if(TextUtils.isEmpty(userName.getText()) || TextUtils.isEmpty(passWord.getText())){
            Toast.makeText(this,"用户名、密码均不能为空",Toast.LENGTH_SHORT).show();
        }else{
            AdminEntity adminEntity = adminDao.findByNameAndPwd(userName.getText().toString(), passWord.getText().toString());
            if(adminEntity != null){
                Toast.makeText(this,"登录成功！",Toast.LENGTH_SHORT).show();
                //启动用户主页
                Intent UserMainIntent = new Intent();
                UserMainIntent.putExtra(SystemConst.ADMIN_ENTITY_ID, adminEntity.getId()); //存入用户id
                UserMainIntent.setClass(this,UserMainActivity.class);
                startActivity(UserMainIntent);
            }else{
                Toast.makeText(this,"用户名或密码错误",Toast.LENGTH_SHORT).show();
            }
        }
    }
}
